package com.example.wan_android.adapter

import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.wan_android.BR
import com.example.wan_android.R
import com.example.wan_android.core.CoreViewHolder
import com.example.wan_android.databinding.AdapterNavBinding
import com.example.wan_android.http.bean.NavItemData
import com.example.wan_android.viewmodel.SystemViewModel

class NavAdapter(vm: SystemViewModel) :
    CoreAdapter<AdapterNavBinding, SystemViewModel, NavItemData>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    var context: Context? = null
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_nav
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val adapter = NavChildrenAdapter(vm = mViewModel!!)
        holder.binding.root.findViewById<RecyclerView>(R.id.rv_nav_children)
            .adapter = adapter
        adapter.setListData(mListData[position].articles)
        holder.binding.root.findViewById<RecyclerView>(R.id.rv_nav_children)
            .layoutManager = GridLayoutManager(context, 3)
    }
}